import Vue from 'vue' // 导入vue
import Router from 'vue-router' // 导入router

// 引入多个动态路由模块
import approvalsRouter from './modules/approvals'
import departmentsRouter from './modules/departments'
import employeesRouter from './modules/employees'
import permissionRouter from './modules/permission'
import attendancesRouter from './modules/attendances'
import salarysRouter from './modules/salarys'
import settingRouter from './modules/setting'
import socialRouter from './modules/social'

// vue全局注册router路由 $route $router
Vue.use(Router)

/* Layout */ // 导入公共组件
import Layout from '@/layout'

// 动态路由表
// 将来会对这个数组筛选
// 动态路由规则
export const asyncRoutes = [

  departmentsRouter,
  settingRouter,
  employeesRouter,
  permissionRouter,
  approvalsRouter,
  attendancesRouter,
  salarysRouter,
  socialRouter
]

// 静态路由表 所有人都可以看到
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        name: 'Dashboard',
        component: () => import('@/views/dashboard/index'),
        meta: { title: '主页', icon: 'dashboard' }
      }

    ]
  },
  {
    path: '/import',
    component: Layout,
    children: [
      {
        path: '',
        component: () => import('@/views/import/index.vue')
      }
    ]

  },
  {
    path: '/detail',
    component: Layout,
    children: [
      {
        path: '',
        component: () => import('@/views/employees/detail.vue')
      }
    ]

  }

  // 404 page must be placed at the end !!!

]

// 创建路由
const createRouter = () => new Router({
  // mode: 'history', // 切换路由模式
  // 切换路由 页面滚动条垂直为0
  scrollBehavior: () => ({ y: 0 }),
  // 路由 规则
  routes: [...constantRoutes]
})

const router = createRouter()
// 重置路由
// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter () {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

// 默认导出路由实列
export default router
